<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${namespace}" >
	<resultMap id="BaseResultMap" type="${domainEntity.fullname}" >
	  	<#list domainEntity.fields as field>
	    <#if field.primaryKey>
	    <id column="${field.colName}" property="${field.name}" jdbcType="${field.colTypeName}" />	
	  	</#if>
	  	<#if !field.primaryKey>
	  	<result column="${field.colName}" property="${field.name}" jdbcType="${field.colTypeName}" />
	    </#if>
    	</#list>
    </resultMap>
    <resultMap id="BaseResultMap_${domainEntity.className}" type="${domainEntity.fullname}" >
	  	<#list domainEntity.fields as field>
	    <#if field.primaryKey>
	    <id column="${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}_${field.colName}" property="${field.name}" jdbcType="${field.colTypeName}" />	
	  	</#if>
	  	<#if !field.primaryKey>
	  	<result column="${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}_${field.colName}" property="${field.name}" jdbcType="${field.colTypeName}" />
	    </#if>
    	</#list>
    </resultMap>
    <sql id="Base_Column_List" >
  		<#list domainEntity.fields as field>${field.colName}<#if field_has_next>,</#if></#list>
	</sql>
  	<sql id="Base_Column_List_${domainEntity.className}" >
  		<#list domainEntity.fields as field>${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}.${field.colName} ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}_${field.colName}<#if field_has_next>,</#if></#list>
	</sql>
	
	<!-- 系统自定义 -->
	<!-- 实体参数查询结果[START] -->
	<resultMap id="ResultMap_FindByQueryParam" type="${domainEntity.fullname}" extends="BaseResultMap_${domainEntity.className}">
		
	</resultMap>

	<sql id="Condition_FindByQueryParam">
		<if test="queryParam.param!=null">
			<bind name="p" value="queryParam.param"/>
        	<#list domainEntity.fields as field>
			<if test="p.${field.name}!=null <#if 'String'==field.propType>and p.${field.name}!=''</#if>">
		    	<#if  'String'==field.propType >
		    	    and ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}.${field.colName} like '%${r'${p'}.${field.name}${r'}'}%'
               <#else>
             		and ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}.${field.colName}<#if 'String'==field.propType> like <#else>=</#if>${r'#{p'}.${field.name}${r'}'}
		    	</#if>
		    </if>
		    </#list>
		</if>
		<if test="queryParam.range!=null">
        			<bind name="range" value="queryParam.range"/>
                	<#list domainEntity.fields as field>

                    <if test="range.${field.name}!=null">
                        and ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)}.${field.colName}  between ${r'#{range'}.${field.name}${r'}'}[0] and ${r'#{range'}.${field.name}${r'}'}[1]
                    </if>
        		    </#list>
        </if>
		<!--
		<bind name="rp" value="queryParam.ruleParam" />
		<include refid="org.mybatis.hbatis.orm.mapper.HbatisMapper.RuleParam"/>
		-->
	</sql>
	<select id="findByQueryParam" resultMap="ResultMap_FindByQueryParam">
		select
		<include refid="Base_Column_List_${domainEntity.className}"></include>
		from ${domainEntity.tableName} ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)} where 1=1
		<include refid="Condition_FindByQueryParam"></include>
		<if test="queryParam.sortOrders!=null and queryParam.sortOrders.size() gt 0">
			order by 
			<foreach collection="queryParam.sortOrders" item="item" separator=",">
				${r'${item.sortField.sqlColumn} ${item.sortType}'}
			</foreach>
		</if>
		<if test="queryParam.limit gt 0">
	  		limit ${r'${queryParam.start},${queryParam.limit}'}
	  	</if>
	</select>
	<select id="countByQueryParam" resultType="long">
		select count(1) from ${domainEntity.tableName} ${NameRuleUtil.getSimpleTableName(domainEntity.tableName)} where 1=1
		<include refid="Condition_FindByQueryParam"></include>
	</select>
	
	<!-- 实体参数查询结果[END] -->
	<!-- 用户自定义 -->
	
</mapper>